/**
 * 
 */
package io;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.StringTokenizer;
import java.util.TreeMap;

import dataTypes.Cluster;

/**
 * @author christian
 * 
 */
public abstract class BlastClustReader {

	public static TreeMap<String, Cluster> readAll(File clusterFile)
			throws IOException {

		return readAll(new BufferedReader(new FileReader(clusterFile)));
	}

	public static TreeMap<String, Cluster> readAll(Reader clusterReader)
			throws IOException {
		TreeMap<String, Cluster> clusterMap = new TreeMap<String, Cluster>();
		BufferedReader reader = new BufferedReader(clusterReader);
		String line;
		while ((line = reader.readLine()) != null) {
			StringTokenizer seq = new StringTokenizer(line);
			String[] clusterSeqs = new String[seq.countTokens()];
			for (int i = 0; i <= seq.countTokens(); i++) {
				clusterSeqs[i] = seq.nextToken();
			}
			clusterMap.put(clusterSeqs[0], new Cluster(clusterSeqs));
		}

		return clusterMap;
	}
}
